define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'clothfee/index' + location.search,
                    add_url: 'clothfee/add',
                    edit_url: 'clothfee/edit',
                    del_url: 'clothfee/del',
                    multi_url: 'clothfee/multi',
                    import_url: 'clothfee/import',
                    table: 'clothfee',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'bank_id', title: __('Bank_id'), sortable: true, formatter: Table.api.formatter.status, searchList: Config.Clothbank},
                        {field: 'type_id', title: __('Type_id'), sortable: true, formatter: Table.api.formatter.status, searchList: Config.Clothtype},
                        {field: 'total_fee', title: __('Total_fee'), operate:'BETWEEN', sortable: true},
                        {field: 'process_fee', title: __('Process_fee'), operate:'BETWEEN', sortable: true},
                        {field: 'cut_fee', title: __('Cut_fee'), operate:'BETWEEN', sortable: true},
                        {field: 'pack_fee', title: __('Pack_fee'), operate:'BETWEEN', sortable: true},
                        {field: 'stamp_fee', title: __('Stamp_fee'), operate:'BETWEEN', sortable: true},
                        {field: 'other_fee', title: __('Other_fee'), operate:'BETWEEN', sortable: true},
                        {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'clothfee/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'clothfee/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'clothfee/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
            $(document).on("change keyup", ".fee", function (e) {
            	var total_nums = 0;
            	total_fee = Number($("#c-process_fee").val()) + Number($("#c-cut_fee").val()) + Number($("#c-pack_fee").val()) +Number($("#c-stamp_fee").val()) + Number($("#c-other_fee").val());
            	$("input[name='row[total_fee]']").val(total_fee);
            });
        },
        edit: function () {
            Controller.api.bindevent();
            $(document).on("change keyup", ".fee", function (e) {
            	var total_nums = 0;
            	total_fee = Number($("#c-process_fee").val()) + Number($("#c-cut_fee").val()) + Number($("#c-pack_fee").val()) +Number($("#c-stamp_fee").val()) + Number($("#c-other_fee").val());
            	$("input[name='row[total_fee]']").val(total_fee);
            });
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
